<template>
	<view class="container">
		<view>
			<view style="margin: 20rpx;">
				请选择图片上传
			</view>
			<uni-section title="只选择图片" >
				<view style="width: 400rpx;height: 400rpx;align-items: center">
					<uni-file-picker @select="select" style="margin-left:50rpx;width: 300rpx;height: 300rpx;"  limit="1" :autoUpload="false" :imageStyles="{width:160}"></uni-file-picker>
				</view>
			</uni-section>
			<view style="width: 300rpx; margin: 0 auto;">
				<button class="uni-button" type="primary" @click="submit">提交</button>
			</view>
		</view>
	</view>
</template>

<script setup>
import { ref } from 'vue';
import {onShow,onLoad} from '@dcloudio/uni-app'
import {baseUrl,checkLogin,handleRequestCode} from '../../static/js/common.js'

	let auth=null
	let file=null

	function select(e){
		file=e.tempFilePaths[0]
	}
	
	function submit(){
		uni.uploadFile({
			url:baseUrl+"/file/uploadSwiper",
			method:'POST',
			name:"file",
			header:{'Authorization':auth},
			filePath:file,
			success:(res)=>{
				handleRequestCode(res.data)
				if(res.data.code==200){
					uni.showToast({
						icon:'success',
						title:'操作成功'
					})
					setTimeout(() => {
						uni.navigateTo({
							url:'/pages/swipperIndex/swipperIndex'
						})
					}, 1000)
				}
			},
			fail(f) {
				console.log(f)
			}
		})
	}
	
	let formData= ref({
					account:'',
					password:'',
					username: '',
					email: '',
					id:''
				})
				
	let rules={
		name:{
			rules: [{
					required: true,
					errorMessage: '请输入姓名',
				}
			]
		},
		// 对email字段进行必填验证
		email: {
			rules: [{
				format: 'email',
				errorMessage: '请输入正确的邮箱地址',
			}]
		}
	}
	
	
	
	onShow(()=>{
		auth=checkLogin()
	})
</script>

<style lang="scss" scoped>
	.container{
		border: 1px solid #ddd;
		padding: 50rpx;
		width: max-content;
		margin: 0 auto;
	}
	input{
		padding-top: 15rpx;
	}
</style>